﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net.Sockets;
using System.Net;
using System.Threading;

namespace ihm
{
    public partial class FenetreConnexion : Form
    {
        public Thread DataReceived = null;
        private CIAI fenetrePrincipale;

        public FenetreConnexion(CIAI _fp)
        {
            fenetrePrincipale = _fp;
            InitializeComponent();
        }

        private void buttonValider_Click(object sender, EventArgs e)
        {
            try
            {
                //Connexion du socket
                fenetrePrincipale.connectClientSocket(this.textBoxIP.Text, this.textBoxPort.Text);
                this.Close();
            }
            catch
            {
                //Le numéro de Port et/ou l'ip n'est pas correctement entré
            }
        }
        private String GetAdr()
        {

            try
            {
                IPHostEntry iphostentry = Dns.GetHostByName(this.textBoxIP.Text);
                String IPStr = "";
                foreach (IPAddress ipaddress in iphostentry.AddressList)
                {
                    IPStr = ipaddress.ToString();
                    return IPStr;
                }
            }
            catch (SocketException E)
            {
                MessageBox.Show(E.Message);
            }
            return "";
        }

        private void buttonAnnuler_Click(object sender, EventArgs e)
        {
            this.Close();

        }
    }
}
